package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlanController
 * @Author lizhiwen
 * @Date 2024-09-09
 */
@RestController
@RequestMapping("/nursing")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;
    @GetMapping("/plan")
    public ResponseResult<NursingPlanVo> findAll(){

        List<NursingPlanVo> list = nursingPlanService.findAll();

        return success(list);

    }

    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> findById(@PathVariable Integer id){
        NursingPlanVo nursingPlanVo = nursingPlanService.findById(id);

        return success(nursingPlanVo);
    }

    @PostMapping("/plan")
    public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @GetMapping("/plan/search")
    public ResponseResult<PageResponse<NursingPlanVo>> page(String name, Integer pageNum, Integer pageSize, Integer status){
        PageResponse<NursingPlanVo> of =  nursingPlanService.page(name, pageNum, pageSize, status);

       return success(of);
    }

    @DeleteMapping("/plan/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        nursingPlanService.deleteById(id);

        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult setStatus(@PathVariable Integer id, @PathVariable Integer status){

        nursingPlanService.setStatus(id, status);

        return success();

    }

}
